# $ANTLR 3.1.3 Mar 17, 2009 19:23:44 subpavadas.g 2011-11-14 20:20:55

import sys
from antlr3 import *
from antlr3.compat import set, frozenset


# for convenience in actions
HIDDEN = BaseRecognizer.HIDDEN

# token types
INTEGER=4
EOF=-1
T__8=8
T__7=7
T__6=6
T__5=5

# token names
tokenNames = [
    "<invalid>", "<EOR>", "<DOWN>", "<UP>", 
    "INTEGER", "'\\n'", "'('", "')'", "'+'"
]




class subpavadasParser(Parser):
    grammarFileName = "subpavadas.g"
    antlr_version = version_str_to_tuple("3.1.3 Mar 17, 2009 19:23:44")
    antlr_version_str = "3.1.3 Mar 17, 2009 19:23:44"
    tokenNames = tokenNames

    def __init__(self, input, state=None, *args, **kwargs):
        if state is None:
            state = RecognizerSharedState()

        super(subpavadasParser, self).__init__(input, state, *args, **kwargs)






                


        



    # $ANTLR start "prog"
    # subpavadas.g:7:1: prog : s '\\n' ;
    def prog(self, ):

        try:
            try:
                # subpavadas.g:7:5: ( s '\\n' )
                # subpavadas.g:7:7: s '\\n'
                pass 
                self._state.following.append(self.FOLLOW_s_in_prog22)
                self.s()

                self._state.following.pop()
                self.match(self.input, 5, self.FOLLOW_5_in_prog23)




            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass
        return 

    # $ANTLR end "prog"


    # $ANTLR start "s"
    # subpavadas.g:8:1: s : ( INTEGER a | '(' b ')' j );
    def s(self, ):

        INTEGER1 = None

        try:
            try:
                # subpavadas.g:8:2: ( INTEGER a | '(' b ')' j )
                alt1 = 2
                LA1_0 = self.input.LA(1)

                if (LA1_0 == INTEGER) :
                    alt1 = 1
                elif (LA1_0 == 6) :
                    alt1 = 2
                else:
                    nvae = NoViableAltException("", 1, 0, self.input)

                    raise nvae

                if alt1 == 1:
                    # subpavadas.g:8:4: INTEGER a
                    pass 
                    INTEGER1=self.match(self.input, INTEGER, self.FOLLOW_INTEGER_in_s29)
                    self._state.following.append(self.FOLLOW_a_in_s31)
                    self.a()

                    self._state.following.pop()
                    #action start
                    print("s -> INTEGER a - " + INTEGER1.text)
                    #action end


                elif alt1 == 2:
                    # subpavadas.g:8:61: '(' b ')' j
                    pass 
                    self.match(self.input, 6, self.FOLLOW_6_in_s37)
                    self._state.following.append(self.FOLLOW_b_in_s38)
                    self.b()

                    self._state.following.pop()
                    self.match(self.input, 7, self.FOLLOW_7_in_s39)
                    self._state.following.append(self.FOLLOW_j_in_s40)
                    self.j()

                    self._state.following.pop()
                    #action start
                    print("s -> (b)j")
                    #action end



            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass
        return 

    # $ANTLR end "s"


    # $ANTLR start "j"
    # subpavadas.g:9:1: j : ( a | );
    def j(self, ):

        try:
            try:
                # subpavadas.g:9:2: ( a | )
                alt2 = 2
                LA2_0 = self.input.LA(1)

                if (LA2_0 == 8) :
                    alt2 = 1
                elif (LA2_0 == 5 or LA2_0 == 7) :
                    alt2 = 2
                else:
                    nvae = NoViableAltException("", 2, 0, self.input)

                    raise nvae

                if alt2 == 1:
                    # subpavadas.g:9:4: a
                    pass 
                    self._state.following.append(self.FOLLOW_a_in_j48)
                    self.a()

                    self._state.following.pop()
                    #action start
                    print("j -> a")
                    #action end


                elif alt2 == 2:
                    # subpavadas.g:9:26: 
                    pass 
                    #action start
                    print("j -> lambda")
                    #action end



            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass
        return 

    # $ANTLR end "j"


    # $ANTLR start "b"
    # subpavadas.g:10:1: b : s ;
    def b(self, ):

        try:
            try:
                # subpavadas.g:10:2: ( s )
                # subpavadas.g:10:4: s
                pass 
                self._state.following.append(self.FOLLOW_s_in_b60)
                self.s()

                self._state.following.pop()
                #action start
                print("b -> s")
                #action end




            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass
        return 

    # $ANTLR end "b"


    # $ANTLR start "a"
    # subpavadas.g:11:1: a : ( '+' a | '+' s | '+' INTEGER );
    def a(self, ):

        INTEGER2 = None

        try:
            try:
                # subpavadas.g:11:2: ( '+' a | '+' s | '+' INTEGER )
                alt3 = 3
                LA3_0 = self.input.LA(1)

                if (LA3_0 == 8) :
                    LA3 = self.input.LA(2)
                    if LA3 == INTEGER:
                        LA3_2 = self.input.LA(3)

                        if (LA3_2 == 5 or LA3_2 == 7) :
                            alt3 = 3
                        elif (LA3_2 == 8) :
                            alt3 = 2
                        else:
                            nvae = NoViableAltException("", 3, 2, self.input)

                            raise nvae

                    elif LA3 == 8:
                        alt3 = 1
                    elif LA3 == 6:
                        alt3 = 2
                    else:
                        nvae = NoViableAltException("", 3, 1, self.input)

                        raise nvae

                else:
                    nvae = NoViableAltException("", 3, 0, self.input)

                    raise nvae

                if alt3 == 1:
                    # subpavadas.g:11:4: '+' a
                    pass 
                    self.match(self.input, 8, self.FOLLOW_8_in_a68)
                    self._state.following.append(self.FOLLOW_a_in_a69)
                    self.a()

                    self._state.following.pop()
                    #action start
                    print("a -> +a")
                    #action end


                elif alt3 == 2:
                    # subpavadas.g:11:30: '+' s
                    pass 
                    self.match(self.input, 8, self.FOLLOW_8_in_a75)
                    self._state.following.append(self.FOLLOW_s_in_a76)
                    self.s()

                    self._state.following.pop()
                    #action start
                    print("a -> +s")
                    #action end


                elif alt3 == 3:
                    # subpavadas.g:11:56: '+' INTEGER
                    pass 
                    self.match(self.input, 8, self.FOLLOW_8_in_a82)
                    INTEGER2=self.match(self.input, INTEGER, self.FOLLOW_INTEGER_in_a83)
                    #action start
                    print("a -> +INTEGER - " + INTEGER2.text)
                    #action end



            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass
        return 

    # $ANTLR end "a"


    # Delegated rules


 

    FOLLOW_s_in_prog22 = frozenset([5])
    FOLLOW_5_in_prog23 = frozenset([1])
    FOLLOW_INTEGER_in_s29 = frozenset([8])
    FOLLOW_a_in_s31 = frozenset([1])
    FOLLOW_6_in_s37 = frozenset([4, 6])
    FOLLOW_b_in_s38 = frozenset([7])
    FOLLOW_7_in_s39 = frozenset([8])
    FOLLOW_j_in_s40 = frozenset([1])
    FOLLOW_a_in_j48 = frozenset([1])
    FOLLOW_s_in_b60 = frozenset([1])
    FOLLOW_8_in_a68 = frozenset([8])
    FOLLOW_a_in_a69 = frozenset([1])
    FOLLOW_8_in_a75 = frozenset([4, 6])
    FOLLOW_s_in_a76 = frozenset([1])
    FOLLOW_8_in_a82 = frozenset([4])
    FOLLOW_INTEGER_in_a83 = frozenset([1])



def main(argv, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr):
    from antlr3.main import ParserMain
    main = ParserMain("subpavadasLexer", subpavadasParser)
    main.stdin = stdin
    main.stdout = stdout
    main.stderr = stderr
    main.execute(argv)


if __name__ == '__main__':
    main(sys.argv)
